home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / gdb / foo / expread.tab.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-01-11  |  68.0 KB  |  2,510 lines

  1.  
  2. /*  A Bison parser, made from expread.y  */
  3.  
  4. #define    INT    258
  5. #define    CHAR    259
  6. #define    UINT    260
  7. #define    FLOAT    261
  8. #define    NAME    262
  9. #define    TYPENAME    263
  10. #define    BLOCKNAME    264
  11. #define    STRING    265
  12. #define    STRUCT    266
  13. #define    UNION    267
  14. #define    ENUM    268
  15. #define    SIZEOF    269
  16. #define    UNSIGNED    270
  17. #define    COLONCOLON    271
  18. #define    SIGNED    272
  19. #define    LONG    273
  20. #define    SHORT    274
  21. #define    INT_KEYWORD    275
  22. #define    LAST    276
  23. #define    REGNAME    277
  24. #define    VARIABLE    278
  25. #define    ASSIGN_MODIFY    279
  26. #define    THIS    280
  27. #define    ABOVE_COMMA    281
  28. #define    OR    282
  29. #define    AND    283
  30. #define    EQUAL    284
  31. #define    NOTEQUAL    285
  32. #define    LEQ    286
  33. #define    GEQ    287
  34. #define    LSH    288
  35. #define    RSH    289
  36. #define    UNARY    290
  37. #define    INCREMENT    291
  38. #define    DECREMENT    292
  39. #define    ARROW    293
  40.  
  41. #line 29 "expread.y"
  42.  
  43. #include <stdio.h>
  44. #include "defs.h"
  45. #include "param.h"
  46. #include "symtab.h"
  47. #include "frame.h"
  48. #include "expression.h"
  49.  
  50. #include <a.out.h>
  51.  
  52. static struct expression *expout;
  53. static int expout_size;
  54. static int expout_ptr;
  55.  
  56. static int yylex ();
  57. static void yyerror ();
  58. static void write_exp_elt ();
  59. static void write_exp_elt_opcode ();
  60. static void write_exp_elt_sym ();
  61. static void write_exp_elt_longcst ();
  62. static void write_exp_elt_dblcst ();
  63. static void write_exp_elt_type ();
  64. static void write_exp_elt_intern ();
  65. static void write_exp_string ();
  66. static void start_arglist ();
  67. static int end_arglist ();
  68. static void free_funcalls ();
  69. static char *copy_name ();
  70.  
  71. /* If this is nonzero, this block is used as the lexical context
  72.    for symbol names.  */
  73.  
  74. static struct block *expression_context_block;
  75.  
  76. /* The innermost context required by the stack and register variables
  77.    we've encountered so far. */
  78. struct block *innermost_block;
  79.  
  80. /* The block in which the most recently discovered symbol was found. */
  81. struct block *block_found;
  82.  
  83. /* Number of arguments seen so far in innermost function call.  */
  84. static int arglist_len;
  85.  
  86. /* Data structure for saving values of arglist_len
  87.    for function calls whose arguments contain other function calls.  */
  88.  
  89. struct funcall
  90.   {
  91.     struct funcall *next;
  92.     int arglist_len;
  93.   };
  94.  
  95. struct funcall *funcall_chain;
  96.  
  97. /* This kind of datum is used to represent the name
  98.    of a symbol token.  */
  99.  
  100. struct stoken
  101.   {
  102.     char *ptr;
  103.     int length;
  104.   };
  105.  
  106. /* For parsing of complicated types.
  107.    An array should be preceded in the list by the size of the array.  */
  108. enum type_pieces
  109.   {tp_end = -1, tp_pointer, tp_reference, tp_array, tp_function};
  110. static enum type_pieces *type_stack;
  111. static int type_stack_depth, type_stack_size;
  112.  
  113. static void push_type ();
  114. static enum type_pieces pop_type ();
  115.  
  116. /* Allow debugging of parsing.  */
  117. #define YYDEBUG 1
  118.  
  119. #line 111 "expread.y"
  120. typedef union
  121.   {
  122.     LONGEST lval;
  123.     unsigned LONGEST ulval;
  124.     double dval;
  125.     struct symbol *sym;
  126.     struct type *tval;
  127.     struct stoken sval;
  128.     int voidval;
  129.     struct block *bval;
  130.     enum exp_opcode opcode;
  131.     struct internalvar *ivar;
  132.  
  133.     struct type **tvec;
  134.     int *ivec;
  135.   } YYSTYPE;
  136.  
  137. #ifndef YYLTYPE
  138. typedef
  139.   struct yyltype
  140.  {
  141.       int timestamp;
  142.       int first_line;
  143.       int first_column;
  144.       int last_line;
  145.       int last_column;
  146.       char *text;
  147.    }
  148.  yyltype;
  149.  
  150. #define YYLTYPE yyltype
  151. #endif
  152.  
  153. #include <stdio.h>
  154.  
  155. #ifndef __STDC__
  156. #define const
  157. #endif
  158.  
  159.  
  160.  
  161. #define    YYFINAL        185
  162. #define    YYFLAG        -32768
  163. #define    YYNTBASE    63
  164.  
  165. #define YYTRANSLATE(x) ((unsigned)(x) <= 293 ? yytranslate[x] : 81)
  166.  
  167. static const char yytranslate[] = {     0,
  168.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  169.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  170.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  171.      2,     2,    56,     2,     2,     2,    48,    34,     2,    55,
  172.     59,    46,    44,    26,    45,    53,    47,     2,     2,     2,
  173.      2,     2,     2,     2,     2,     2,     2,    62,     2,    37,
  174.     28,    38,    29,    43,     2,     2,     2,     2,     2,     2,
  175.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  176.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  177.     54,     2,    58,    33,     2,     2,     2,     2,     2,     2,
  178.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  179.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  180.      2,     2,    60,    32,    61,    57,     2,     2,     2,     2,
  181.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  182.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  183.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  184.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  185.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  186.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  187.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  188.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  189.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  190.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  191.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  192.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  193.      2,     2,     2,     2,     2,     1,     2,     3,     4,     5,
  194.      6,     7,     8,     9,    10,    11,    12,    13,    14,    15,
  195.     16,    17,    18,    19,    20,    21,    22,    23,    24,    25,
  196.     27,    30,    31,    35,    36,    39,    40,    41,    42,    49,
  197.     50,    51,    52
  198. };
  199.  
  200. #if YYDEBUG != 0
  201. static const short yyrline[] = { 0,
  202.    190,   194,   195,   200,   203,   206,   210,   214,   218,   222,
  203.    226,   230,   234,   238,   244,   248,   254,   258,   262,   266,
  204.    272,   275,   279,   283,   289,   295,   301,   305,   309,   313,
  205.    317,   321,   325,   329,   333,   337,   341,   345,   349,   353,
  206.    357,   361,   365,   369,   373,   377,   381,   385,   391,   401,
  207.    413,   420,   427,   430,   436,   442,   448,   455,   462,   469,
  208.    490,   499,   510,   523,   569,   646,   647,   682,   684,   686,
  209.    689,   691,   696,   702,   704,   708,   710,   714,   718,   719,
  210.    721,   723,   726,   733,   736,   738,   740,   742,   744,   746,
  211.    748,   750,   753,   756,   759,   761,   763,   766,   770,   771,
  212.    776,   781,   789,   794,   801,   802,   803,   806,   807
  213. };
  214.  
  215. static const char * const yytname[] = {     0,
  216. "error","$illegal.","INT","CHAR","UINT","FLOAT","NAME","TYPENAME","BLOCKNAME","STRING",
  217. "STRUCT","UNION","ENUM","SIZEOF","UNSIGNED","COLONCOLON","SIGNED","LONG","SHORT","INT_KEYWORD",
  218. "LAST","REGNAME","VARIABLE","ASSIGN_MODIFY","THIS","','","ABOVE_COMMA","'='","'?'","OR",
  219. "AND","'|'","'^'","'&'","EQUAL","NOTEQUAL","'<'","'>'","LEQ","GEQ",
  220. "LSH","RSH","'@'","'+'","'-'","'*'","'/'","'%'","UNARY","INCREMENT",
  221. "DECREMENT","ARROW","'.'","'['","'('","'!'","'~'","']'","')'","'{'",
  222. "'}'","':'","start"
  223. };
  224. #endif
  225.  
  226. static const short yyr1[] = {     0,
  227.     63,    64,    64,    65,    65,    65,    65,    65,    65,    65,
  228.     65,    65,    65,    65,    65,    65,    65,    65,    66,    65,
  229.     67,    67,    67,    65,    65,    65,    65,    65,    65,    65,
  230.     65,    65,    65,    65,    65,    65,    65,    65,    65,    65,
  231.     65,    65,    65,    65,    65,    65,    65,    65,    65,    65,
  232.     65,    65,    65,    65,    65,    65,    65,    65,    65,    68,
  233.     68,    69,    69,    69,    69,    70,    70,    71,    71,    71,
  234.     72,    72,    72,    72,    72,    73,    73,    74,    75,    75,
  235.     75,    75,    75,    76,    76,    76,    76,    76,    76,    76,
  236.     76,    76,    76,    76,    76,    76,    76,    76,    77,    77,
  237.     77,    77,    78,    78,    79,    79,    79,    80,    80
  238. };
  239.  
  240. static const short yyr2[] = {     0,
  241.      1,     1,     3,     2,     2,     2,     2,     2,     2,     2,
  242.      2,     2,     2,     3,     4,     3,     4,     4,     0,     5,
  243.      0,     1,     3,     4,     4,     3,     3,     3,     3,     3,
  244.      3,     3,     3,     3,     3,     3,     3,     3,     3,     3,
  245.      3,     3,     3,     3,     3,     5,     3,     3,     1,     1,
  246.      1,     1,     1,     1,     1,     1,     4,     1,     1,     1,
  247.      3,     3,     3,     2,     1,     1,     2,     1,     2,     1,
  248.      3,     2,     1,     2,     1,     2,     3,     2,     1,     3,
  249.      6,     8,     9,     1,     1,     1,     1,     2,     3,     2,
  250.      3,     2,     2,     2,     2,     1,     2,     1,     1,     1,
  251.      1,     1,     1,     3,     1,     1,     1,     1,     1
  252. };
  253.  
  254. static const short yydefact[] = {     0,
  255.     49,    51,    50,    52,   108,    84,   109,    58,     0,     0,
  256.      0,     0,    96,     0,    98,    86,    87,    85,    54,    55,
  257.     56,    59,     0,     0,     0,     0,     0,     0,     0,     0,
  258.      0,     1,     2,     0,    53,     0,    65,   105,   107,   106,
  259.     92,    93,    94,     0,    13,    99,   101,   102,   100,    95,
  260.     64,   101,   102,    97,    88,    90,     5,     6,     4,     9,
  261.     10,     0,    79,     0,    66,     7,     8,     0,    66,     0,
  262.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  263.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  264.      0,     0,    11,    12,     0,     0,     0,    19,     0,     0,
  265.      0,    89,    91,    26,     0,     0,     0,    68,     0,     0,
  266.     67,    70,    73,    75,     0,     0,     3,    48,    47,     0,
  267.     45,    44,    43,    42,    41,    35,    36,    39,    40,    37,
  268.     38,    33,    34,    27,    31,    32,    28,    29,    30,     0,
  269.     14,     0,    16,     0,    21,    62,    63,    57,     0,    25,
  270.     80,    69,     0,    76,    78,     0,     0,    72,    74,    24,
  271.      0,    15,    17,    18,    22,     0,     0,    77,    71,    46,
  272.      0,    20,     0,    23,    81,     0,    82,   103,     0,     0,
  273.     83,   104,     0,     0,     0
  274. };
  275.  
  276. static const short yydefgoto[] = {   183,
  277.     62,    33,   145,   166,    34,    35,    63,   111,   112,   113,
  278.    114,    64,    36,    50,   179,   147,    37
  279. };
  280.  
  281. static const short yypact[] = {   157,
  282. -32768,-32768,-32768,-32768,-32768,-32768,   -13,-32768,   105,   105,
  283.    105,   215,    82,   105,   178,   -10,    -4,-32768,-32768,-32768,
  284. -32768,-32768,   157,   157,   157,   157,   157,   157,   157,   157,
  285.    239,     6,   284,    75,-32768,    79,-32768,-32768,-32768,-32768,
  286. -32768,-32768,-32768,   157,   501,-32768,    66,    84,-32768,-32768,
  287. -32768,-32768,-32768,-32768,-32768,-32768,   501,   501,   501,   501,
  288.    501,    67,-32768,   -50,    69,   501,   501,   -53,   138,   157,
  289.    157,   157,   157,   157,   157,   157,   157,   157,   157,   157,
  290.    157,   157,   157,   157,   157,   157,   157,   157,   157,   157,
  291.    157,   157,-32768,-32768,   111,   197,   157,-32768,   105,   105,
  292.    -28,-32768,-32768,-32768,   239,   157,   202,   -21,    26,    51,
  293. -32768,    62,-32768,-32768,   157,    63,   284,   284,   284,   249,
  294.    336,   360,   383,   405,   426,   445,   445,   460,   460,   460,
  295.    460,   473,   473,   485,   495,   495,   501,   501,   501,   157,
  296. -32768,   157,-32768,    -2,   157,   106,-32768,    32,   109,   501,
  297. -32768,-32768,    77,-32768,-32768,    68,    72,-32768,-32768,   501,
  298.    157,   501,   501,-32768,   284,    70,    94,-32768,-32768,   311,
  299.    157,-32768,    83,   284,    92,   126,-32768,    93,    73,   239,
  300. -32768,    93,   121,   150,-32768
  301. };
  302.  
  303. static const short yypgoto[] = {-32768,
  304.      1,   -12,-32768,-32768,-32768,-32768,-32768,   -80,-32768,    41,
  305.     46,   -25,   -24,   166,-32768,    12,-32768
  306. };
  307.  
  308.  
  309. #define    YYLAST        556
  310.  
  311.  
  312. static const short yytable[] = {    45,
  313.     32,   105,   -60,    65,   105,    68,    69,   115,   106,    55,
  314.     57,    58,    59,    60,    61,    56,    66,    67,   101,    65,
  315.     41,    42,    43,    70,   108,    51,   105,   152,   153,   156,
  316.    148,    70,   109,   110,     1,     2,     3,     4,     5,     6,
  317.      7,     8,     9,    10,    11,    12,    13,    14,    15,    16,
  318.     17,    18,    19,    20,    21,   164,    22,   117,   118,   119,
  319.    120,   121,   122,   123,   124,   125,   126,   127,   128,   129,
  320.    130,   131,   132,   133,   134,   135,   136,   137,   138,   139,
  321.    149,    26,    27,   154,   107,   102,    28,    29,    30,    46,
  322.     99,    31,    70,   150,   100,   171,   108,   144,   180,    47,
  323.     48,    49,   160,   103,   109,   110,   141,   143,   151,   155,
  324.    146,    38,    39,    40,   108,   109,   157,    38,    39,    40,
  325.    184,   -61,   109,   110,   167,   104,   169,   162,   172,   163,
  326.    155,   181,   165,     6,   168,   150,     9,    10,    11,   173,
  327.     13,   175,    15,    16,    17,    18,   176,   105,   170,   185,
  328.    178,    69,   158,   116,   182,    69,   140,   159,   174,     1,
  329.      2,     3,     4,     5,     6,     7,     8,     9,    10,    11,
  330.     12,    13,    14,    15,    16,    17,    18,    19,    20,    21,
  331.     54,    22,     0,   108,   177,    46,     0,     0,     0,     0,
  332.     23,   109,   110,     0,     0,    52,    53,    49,     0,     0,
  333.      0,    24,    25,    38,    39,    40,    26,    27,    38,    39,
  334.     40,    28,    29,    30,     0,     0,    31,     1,     2,     3,
  335.      4,     5,     6,     7,     8,     9,    10,    11,    12,    13,
  336.     14,    15,    16,    17,    18,    19,    20,    21,     0,    22,
  337.      0,     0,   142,     0,     0,     0,     6,   151,    23,     9,
  338.     10,    11,     0,    13,     0,    15,    16,    17,    18,    24,
  339.     25,     0,     0,     0,    26,    27,     0,     0,     0,    44,
  340.     29,    30,    71,     0,    31,     0,    72,    73,    74,    75,
  341.     76,    77,    78,    79,    80,    81,    82,    83,    84,    85,
  342.     86,    87,    88,    89,    90,    91,    92,     0,    93,    94,
  343.     95,    96,    97,    98,     0,     0,     0,    71,     0,     0,
  344.    161,    72,    73,    74,    75,    76,    77,    78,    79,    80,
  345.     81,    82,    83,    84,    85,    86,    87,    88,    89,    90,
  346.     91,    92,     0,    93,    94,    95,    96,    97,    98,    73,
  347.     74,    75,    76,    77,    78,    79,    80,    81,    82,    83,
  348.     84,    85,    86,    87,    88,    89,    90,    91,    92,     0,
  349.     93,    94,    95,    96,    97,    98,    75,    76,    77,    78,
  350.     79,    80,    81,    82,    83,    84,    85,    86,    87,    88,
  351.     89,    90,    91,    92,     0,    93,    94,    95,    96,    97,
  352.     98,    76,    77,    78,    79,    80,    81,    82,    83,    84,
  353.     85,    86,    87,    88,    89,    90,    91,    92,     0,    93,
  354.     94,    95,    96,    97,    98,    77,    78,    79,    80,    81,
  355.     82,    83,    84,    85,    86,    87,    88,    89,    90,    91,
  356.     92,     0,    93,    94,    95,    96,    97,    98,    78,    79,
  357.     80,    81,    82,    83,    84,    85,    86,    87,    88,    89,
  358.     90,    91,    92,     0,    93,    94,    95,    96,    97,    98,
  359.     79,    80,    81,    82,    83,    84,    85,    86,    87,    88,
  360.     89,    90,    91,    92,     0,    93,    94,    95,    96,    97,
  361.     98,    81,    82,    83,    84,    85,    86,    87,    88,    89,
  362.     90,    91,    92,     0,    93,    94,    95,    96,    97,    98,
  363.     85,    86,    87,    88,    89,    90,    91,    92,     0,    93,
  364.     94,    95,    96,    97,    98,    87,    88,    89,    90,    91,
  365.     92,     0,    93,    94,    95,    96,    97,    98,    88,    89,
  366.     90,    91,    92,     0,    93,    94,    95,    96,    97,    98,
  367.     90,    91,    92,     0,    93,    94,    95,    96,    97,    98,
  368.     93,    94,    95,    96,    97,    98
  369. };
  370.  
  371. static const short yycheck[] = {    12,
  372.      0,    55,    16,    28,    55,    31,    31,    61,    59,    20,
  373.     23,    24,    25,    26,    27,    20,    29,    30,    44,    44,
  374.      9,    10,    11,    26,    46,    14,    55,   108,     3,   110,
  375.     59,    26,    54,    55,     3,     4,     5,     6,     7,     8,
  376.      9,    10,    11,    12,    13,    14,    15,    16,    17,    18,
  377.     19,    20,    21,    22,    23,    58,    25,    70,    71,    72,
  378.     73,    74,    75,    76,    77,    78,    79,    80,    81,    82,
  379.     83,    84,    85,    86,    87,    88,    89,    90,    91,    92,
  380.    105,    50,    51,    58,    16,    20,    55,    56,    57,     8,
  381.     16,    60,    26,   106,    16,    26,    46,    97,    26,    18,
  382.     19,    20,   115,    20,    54,    55,    95,    96,    46,    59,
  383.     99,     7,     8,     9,    46,    54,    55,     7,     8,     9,
  384.      0,    16,    54,    55,    16,    59,    59,   140,    59,   142,
  385.     59,    59,   145,     8,    58,   148,    11,    12,    13,    46,
  386.     15,    59,    17,    18,    19,    20,    55,    55,   161,     0,
  387.    176,   176,   112,    16,   180,   180,    46,   112,   171,     3,
  388.      4,     5,     6,     7,     8,     9,    10,    11,    12,    13,
  389.     14,    15,    16,    17,    18,    19,    20,    21,    22,    23,
  390.     15,    25,    -1,    46,    59,     8,    -1,    -1,    -1,    -1,
  391.     34,    54,    55,    -1,    -1,    18,    19,    20,    -1,    -1,
  392.     -1,    45,    46,     7,     8,     9,    50,    51,     7,     8,
  393.      9,    55,    56,    57,    -1,    -1,    60,     3,     4,     5,
  394.      6,     7,     8,     9,    10,    11,    12,    13,    14,    15,
  395.     16,    17,    18,    19,    20,    21,    22,    23,    -1,    25,
  396.     -1,    -1,    46,    -1,    -1,    -1,     8,    46,    34,    11,
  397.     12,    13,    -1,    15,    -1,    17,    18,    19,    20,    45,
  398.     46,    -1,    -1,    -1,    50,    51,    -1,    -1,    -1,    55,
  399.     56,    57,    24,    -1,    60,    -1,    28,    29,    30,    31,
  400.     32,    33,    34,    35,    36,    37,    38,    39,    40,    41,
  401.     42,    43,    44,    45,    46,    47,    48,    -1,    50,    51,
  402.     52,    53,    54,    55,    -1,    -1,    -1,    24,    -1,    -1,
  403.     62,    28,    29,    30,    31,    32,    33,    34,    35,    36,
  404.     37,    38,    39,    40,    41,    42,    43,    44,    45,    46,
  405.     47,    48,    -1,    50,    51,    52,    53,    54,    55,    29,
  406.     30,    31,    32,    33,    34,    35,    36,    37,    38,    39,
  407.     40,    41,    42,    43,    44,    45,    46,    47,    48,    -1,
  408.     50,    51,    52,    53,    54,    55,    31,    32,    33,    34,
  409.     35,    36,    37,    38,    39,    40,    41,    42,    43,    44,
  410.     45,    46,    47,    48,    -1,    50,    51,    52,    53,    54,
  411.     55,    32,    33,    34,    35,    36,    37,    38,    39,    40,
  412.     41,    42,    43,    44,    45,    46,    47,    48,    -1,    50,
  413.     51,    52,    53,    54,    55,    33,    34,    35,    36,    37,
  414.     38,    39,    40,    41,    42,    43,    44,    45,    46,    47,
  415.     48,    -1,    50,    51,    52,    53,    54,    55,    34,    35,
  416.     36,    37,    38,    39,    40,    41,    42,    43,    44,    45,
  417.     46,    47,    48,    -1,    50,    51,    52,    53,    54,    55,
  418.     35,    36,    37,    38,    39,    40,    41,    42,    43,    44,
  419.     45,    46,    47,    48,    -1,    50,    51,    52,    53,    54,
  420.     55,    37,    38,    39,    40,    41,    42,    43,    44,    45,
  421.     46,    47,    48,    -1,    50,    51,    52,    53,    54,    55,
  422.     41,    42,    43,    44,    45,    46,    47,    48,    -1,    50,
  423.     51,    52,    53,    54,    55,    43,    44,    45,    46,    47,
  424.     48,    -1,    50,    51,    52,    53,    54,    55,    44,    45,
  425.     46,    47,    48,    -1,    50,    51,    52,    53,    54,    55,
  426.     46,    47,    48,    -1,    50,    51,    52,    53,    54,    55,
  427.     50,    51,    52,    53,    54,    55
  428. };
  429. #define YYPURE 1
  430.  
  431. /* -*-C-*-  Note some compilers choke on comments on `#line' lines.  */
  432. #line 3 "bison.simple"
  433.  
  434. /* Skeleton output parser for bison,
  435.    Copyright (C) 1984 Bob Corbett and Richard Stallman
  436.  
  437.    This program is free software; you can redistribute it and/or modify
  438.    it under the terms of the GNU General Public License as published by
  439.    the Free Software Foundation; either version 1, or (at your option)
  440.    any later version.
  441.  
  442.    This program is distributed in the hope that it will be useful,
  443.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  444.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  445.    GNU General Public License for more details.
  446.  
  447.    You should have received a copy of the GNU General Public License
  448.    along with this program; if not, write to the Free Software
  449.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  450.  
  451.  
  452. #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__)
  453. #include <alloca.h>
  454. #endif
  455.  
  456. /* This is the parser code that is written into each bison parser
  457.   when the %semantic_parser declaration is not specified in the grammar.
  458.   It was written by Richard Stallman by simplifying the hairy parser
  459.   used when %semantic_parser is specified.  */
  460.  
  461. /* Note: there must be only one dollar sign in this file.
  462.    It is replaced by the list of actions, each action
  463.    as one case of the switch.  */
  464.  
  465. #define yyerrok        (yyerrstatus = 0)
  466. #define yyclearin    (yychar = YYEMPTY)
  467. #define YYEMPTY        -2
  468. #define YYEOF        0
  469. #define YYFAIL        goto yyerrlab;
  470. #define YYACCEPT    return(0)
  471. #define YYABORT     return(1)
  472. #define YYERROR        goto yyerrlab
  473.  
  474. #define YYTERROR    1
  475. #define YYERRCODE    256
  476.  
  477. #ifndef YYIMPURE
  478. #define YYLEX        yylex()
  479. #endif
  480.  
  481. #ifndef YYPURE
  482. #define YYLEX        yylex(&yylval, &yylloc)
  483. #endif
  484.  
  485. /* If nonreentrant, generate the variables here */
  486.  
  487. #ifndef YYIMPURE
  488.  
  489. int    yychar;            /*  the lookahead symbol        */
  490. YYSTYPE    yylval;            /*  the semantic value of the        */
  491.                 /*  lookahead symbol            */
  492.  
  493. YYLTYPE yylloc;            /*  location data for the lookahead    */
  494.                 /*  symbol                */
  495.  
  496. int yynerrs;            /*  number of parse errors so far       */
  497. #endif  /* YYIMPURE */
  498.  
  499. #if YYDEBUG != 0
  500. int yydebug;            /*  nonzero means print parse trace    */
  501. /* Since this is uninitialized, it does not stop multiple parsers
  502.    from coexisting.  */
  503. #endif
  504.  
  505. /*  YYMAXDEPTH indicates the initial size of the parser's stacks    */
  506.  
  507. #ifndef    YYMAXDEPTH
  508. #define YYMAXDEPTH 200
  509. #endif
  510.  
  511. /*  YYMAXLIMIT is the maximum size the stacks can grow to
  512.     (effective only if the built-in stack extension method is used).  */
  513.  
  514. #ifndef YYMAXLIMIT
  515. #define YYMAXLIMIT 10000
  516. #endif
  517.  
  518.  
  519. #line 90 "bison.simple"
  520. int
  521. yyparse()
  522. {
  523.   register int yystate;
  524.   register int yyn;
  525.   register short *yyssp;
  526.   register YYSTYPE *yyvsp;
  527.   YYLTYPE *yylsp;
  528.   int yyerrstatus;    /*  number of tokens to shift before error messages enabled */
  529.   int yychar1;        /*  lookahead token as an internal (translated) token number */
  530.  
  531.   short    yyssa[YYMAXDEPTH];    /*  the state stack            */
  532.   YYSTYPE yyvsa[YYMAXDEPTH];    /*  the semantic value stack        */
  533.   YYLTYPE yylsa[YYMAXDEPTH];    /*  the location stack            */
  534.  
  535.   short *yyss = yyssa;        /*  refer to the stacks thru separate pointers */
  536.   YYSTYPE *yyvs = yyvsa;    /*  to allow yyoverflow to reallocate them elsewhere */
  537.   YYLTYPE *yyls = yylsa;
  538.  
  539.   int yymaxdepth = YYMAXDEPTH;
  540.  
  541. #ifndef YYPURE
  542.   int yychar;
  543.   YYSTYPE yylval;
  544.   YYLTYPE yylloc;
  545.   int yynerrs;
  546. #endif
  547.  
  548.   YYSTYPE yyval;        /*  the variable used to return        */
  549.                 /*  semantic values from the action    */
  550.                 /*  routines                */
  551.  
  552.   int yylen;
  553.  
  554. #if YYDEBUG != 0
  555.   if (yydebug)
  556.     fprintf(stderr, "Starting parse\n");
  557. #endif
  558.  
  559.   yystate = 0;
  560.   yyerrstatus = 0;
  561.   yynerrs = 0;
  562.   yychar = YYEMPTY;        /* Cause a token to be read.  */
  563.  
  564.   /* Initialize stack pointers.
  565.      Waste one element of value and location stack
  566.      so that they stay on the same level as the state stack.  */
  567.  
  568.   yyssp = yyss - 1;
  569.   yyvsp = yyvs;
  570.   yylsp = yyls;
  571.  
  572. /* Push a new state, which is found in  yystate  .  */
  573. /* In all cases, when you get here, the value and location stacks
  574.    have just been pushed. so pushing a state here evens the stacks.  */
  575. yynewstate:
  576.  
  577.   *++yyssp = yystate;
  578.  
  579.   if (yyssp >= yyss + yymaxdepth - 1)
  580.     {
  581.       /* Give user a chance to reallocate the stack */
  582.       /* Use copies of these so that the &'s don't force the real ones into memory. */
  583.       YYSTYPE *yyvs1 = yyvs;
  584.       YYLTYPE *yyls1 = yyls;
  585.       short *yyss1 = yyss;
  586.  
  587.       /* Get the current used size of the three stacks, in elements.  */
  588.       int size = yyssp - yyss + 1;
  589.  
  590. #ifdef yyoverflow
  591.       /* Each stack pointer address is followed by the size of
  592.      the data in use in that stack, in bytes.  */
  593.       yyoverflow("parser stack overflow",
  594.          &yyss1, size * sizeof (*yyssp),
  595.          &yyvs1, size * sizeof (*yyvsp),
  596.          &yyls1, size * sizeof (*yylsp),
  597.          &yymaxdepth);
  598.  
  599.       yyss = yyss1; yyvs = yyvs1; yyls = yyls1;
  600. #else /* no yyoverflow */
  601.       /* Extend the stack our own way.  */
  602.       if (yymaxdepth >= YYMAXLIMIT)
  603.     yyerror("parser stack overflow");
  604.       yymaxdepth *= 2;
  605.       if (yymaxdepth > YYMAXLIMIT)
  606.     yymaxdepth = YYMAXLIMIT;
  607.       yyss = (short *) alloca (yymaxdepth * sizeof (*yyssp));
  608.       bcopy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp));
  609.       yyvs = (YYSTYPE *) alloca (yymaxdepth * sizeof (*yyvsp));
  610.       bcopy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp));
  611. #ifdef YYLSP_NEEDED
  612.       yyls = (YYLTYPE *) alloca (yymaxdepth * sizeof (*yylsp));
  613.       bcopy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp));
  614. #endif
  615. #endif /* no yyoverflow */
  616.  
  617.       yyssp = yyss + size - 1;
  618.       yyvsp = yyvs + size - 1;
  619. #ifdef YYLSP_NEEDED
  620.       yylsp = yyls + size - 1;
  621. #endif
  622.  
  623. #if YYDEBUG != 0
  624.       if (yydebug)
  625.     fprintf(stderr, "Stack size increased to %d\n", yymaxdepth);
  626. #endif
  627.  
  628.       if (yyssp >= yyss + yymaxdepth - 1)
  629.     YYABORT;
  630.     }
  631.  
  632. #if YYDEBUG != 0
  633.   if (yydebug)
  634.     fprintf(stderr, "Entering state %d\n", yystate);
  635. #endif
  636.  
  637. /* Do appropriate processing given the current state.  */
  638. /* Read a lookahead token if we need one and don't already have one.  */
  639. yyresume:
  640.  
  641.   /* First try to decide what to do without reference to lookahead token.  */
  642.  
  643.   yyn = yypact[yystate];
  644.   if (yyn == YYFLAG)
  645.     goto yydefault;
  646.  
  647.   /* Not known => get a lookahead token if don't already have one.  */
  648.  
  649.   /* yychar is either YYEMPTY or YYEOF
  650.      or a valid token in external form.  */
  651.  
  652.   if (yychar == YYEMPTY)
  653.     {
  654. #if YYDEBUG != 0
  655.       if (yydebug)
  656.     fprintf(stderr, "Reading a token: ");
  657. #endif
  658.       yychar = YYLEX;
  659.     }
  660.  
  661.   /* Convert token to internal form (in yychar1) for indexing tables with */
  662.  
  663.   if (yychar <= 0)        /* This means end of input. */
  664.     {
  665.       yychar1 = 0;
  666.       yychar = YYEOF;        /* Don't call YYLEX any more */
  667.  
  668. #if YYDEBUG != 0
  669.       if (yydebug)
  670.     fprintf(stderr, "Now at end of input.\n");
  671. #endif
  672.     }
  673.   else
  674.     {
  675.       yychar1 = YYTRANSLATE(yychar);
  676.  
  677. #if YYDEBUG != 0
  678.       if (yydebug)
  679.     fprintf(stderr, "Next token is %d (%s)\n", yychar, yytname[yychar1]);
  680. #endif
  681.     }
  682.  
  683.   yyn += yychar1;
  684.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
  685.     goto yydefault;
  686.  
  687.   yyn = yytable[yyn];
  688.  
  689.   /* yyn is what to do for this token type in this state.
  690.      Negative => reduce, -yyn is rule number.
  691.      Positive => shift, yyn is new state.
  692.        New state is final state => don't bother to shift,
  693.        just return success.
  694.      0, or most negative number => error.  */
  695.  
  696.   if (yyn < 0)
  697.     {
  698.       if (yyn == YYFLAG)
  699.     goto yyerrlab;
  700.       yyn = -yyn;
  701.       goto yyreduce;
  702.     }
  703.   else if (yyn == 0)
  704.     goto yyerrlab;
  705.  
  706.   if (yyn == YYFINAL)
  707.     YYACCEPT;
  708.  
  709.   /* Shift the lookahead token.  */
  710.  
  711. #if YYDEBUG != 0
  712.   if (yydebug)
  713.     fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
  714. #endif
  715.  
  716.   /* Discard the token being shifted unless it is eof.  */
  717.   if (yychar != YYEOF)
  718.     yychar = YYEMPTY;
  719.  
  720.   *++yyvsp = yylval;
  721. #ifdef YYLSP_NEEDED
  722.   *++yylsp = yylloc;
  723. #endif
  724.  
  725.   /* count tokens shifted since error; after three, turn off error status.  */
  726.   if (yyerrstatus) yyerrstatus--;
  727.  
  728.   yystate = yyn;
  729.   goto yynewstate;
  730.  
  731. /* Do the default action for the current state.  */
  732. yydefault:
  733.  
  734.   yyn = yydefact[yystate];
  735.   if (yyn == 0)
  736.     goto yyerrlab;
  737.  
  738. /* Do a reduction.  yyn is the number of a rule to reduce with.  */
  739. yyreduce:
  740.   yylen = yyr2[yyn];
  741.   yyval = yyvsp[1-yylen]; /* implement default value of the action */
  742.  
  743. #if YYDEBUG != 0
  744.   if (yydebug)
  745.     {
  746.       if (yylen == 1)
  747.     fprintf (stderr, "Reducing 1 value via line %d, ",
  748.          yyrline[yyn]);
  749.       else
  750.     fprintf (stderr, "Reducing %d values via line %d, ",
  751.          yylen, yyrline[yyn]);
  752.     }
  753. #endif
  754.  
  755.  
  756.   switch (yyn) {
  757.  
  758. case 3:
  759. #line 196 "expread.y"
  760. { write_exp_elt_opcode (BINOP_COMMA); ;
  761.     break;}
  762. case 4:
  763. #line 201 "expread.y"
  764. { write_exp_elt_opcode (UNOP_IND); ;
  765.     break;}
  766. case 5:
  767. #line 204 "expread.y"
  768. { write_exp_elt_opcode (UNOP_ADDR); ;
  769.     break;}
  770. case 6:
  771. #line 207 "expread.y"
  772. { write_exp_elt_opcode (UNOP_NEG); ;
  773.     break;}
  774. case 7:
  775. #line 211 "expread.y"
  776. { write_exp_elt_opcode (UNOP_ZEROP); ;
  777.     break;}
  778. case 8:
  779. #line 215 "expread.y"
  780. { write_exp_elt_opcode (UNOP_LOGNOT); ;
  781.     break;}
  782. case 9:
  783. #line 219 "expread.y"
  784. { write_exp_elt_opcode (UNOP_PREINCREMENT); ;
  785.     break;}
  786. case 10:
  787. #line 223 "expread.y"
  788. { write_exp_elt_opcode (UNOP_PREDECREMENT); ;
  789.     break;}
  790. case 11:
  791. #line 227 "expread.y"
  792. { write_exp_elt_opcode (UNOP_POSTINCREMENT); ;
  793.     break;}
  794. case 12:
  795. #line 231 "expread.y"
  796. { write_exp_elt_opcode (UNOP_POSTDECREMENT); ;
  797.     break;}
  798. case 13:
  799. #line 235 "expread.y"
  800. { write_exp_elt_opcode (UNOP_SIZEOF); ;
  801.     break;}
  802. case 14:
  803. #line 239 "expread.y"
  804. { write_exp_elt_opcode (STRUCTOP_PTR);
  805.               write_exp_string (yyvsp[0].sval);
  806.               write_exp_elt_opcode (STRUCTOP_PTR); ;
  807.     break;}
  808. case 15:
  809. #line 245 "expread.y"
  810. { write_exp_elt_opcode (STRUCTOP_MPTR); ;
  811.     break;}
  812. case 16:
  813. #line 249 "expread.y"
  814. { write_exp_elt_opcode (STRUCTOP_STRUCT);
  815.               write_exp_string (yyvsp[0].sval);
  816.               write_exp_elt_opcode (STRUCTOP_STRUCT); ;
  817.     break;}
  818. case 17:
  819. #line 255 "expread.y"
  820. { write_exp_elt_opcode (STRUCTOP_MEMBER); ;
  821.     break;}
  822. case 18:
  823. #line 259 "expread.y"
  824. { write_exp_elt_opcode (BINOP_SUBSCRIPT); ;
  825.     break;}
  826. case 19:
  827. #line 265 "expread.y"
  828. { start_arglist (); ;
  829.     break;}
  830. case 20:
  831. #line 267 "expread.y"
  832. { write_exp_elt_opcode (OP_FUNCALL);
  833.               write_exp_elt_longcst ((LONGEST) end_arglist ());
  834.               write_exp_elt_opcode (OP_FUNCALL); ;
  835.     break;}
  836. case 22:
  837. #line 276 "expread.y"
  838. { arglist_len = 1; ;
  839.     break;}
  840. case 23:
  841. #line 280 "expread.y"
  842. { arglist_len++; ;
  843.     break;}
  844. case 24:
  845. #line 284 "expread.y"
  846. { write_exp_elt_opcode (UNOP_MEMVAL);
  847.               write_exp_elt_type (yyvsp[-2].tval);
  848.               write_exp_elt_opcode (UNOP_MEMVAL); ;
  849.     break;}
  850. case 25:
  851. #line 290 "expread.y"
  852. { write_exp_elt_opcode (UNOP_CAST);
  853.               write_exp_elt_type (yyvsp[-2].tval);
  854.               write_exp_elt_opcode (UNOP_CAST); ;
  855.     break;}
  856. case 26:
  857. #line 296 "expread.y"
  858. { ;
  859.     break;}
  860. case 27:
  861. #line 302 "expread.y"
  862. { write_exp_elt_opcode (BINOP_REPEAT); ;
  863.     break;}
  864. case 28:
  865. #line 306 "expread.y"
  866. { write_exp_elt_opcode (BINOP_MUL); ;
  867.     break;}
  868. case 29:
  869. #line 310 "expread.y"
  870. { write_exp_elt_opcode (BINOP_DIV); ;
  871.     break;}
  872. case 30:
  873. #line 314 "expread.y"
  874. { write_exp_elt_opcode (BINOP_REM); ;
  875.     break;}
  876. case 31:
  877. #line 318 "expread.y"
  878. { write_exp_elt_opcode (BINOP_ADD); ;
  879.     break;}
  880. case 32:
  881. #line 322 "expread.y"
  882. { write_exp_elt_opcode (BINOP_SUB); ;
  883.     break;}
  884. case 33:
  885. #line 326 "expread.y"
  886. { write_exp_elt_opcode (BINOP_LSH); ;
  887.     break;}
  888. case 34:
  889. #line 330 "expread.y"
  890. { write_exp_elt_opcode (BINOP_RSH); ;
  891.     break;}
  892. case 35:
  893. #line 334 "expread.y"
  894. { write_exp_elt_opcode (BINOP_EQUAL); ;
  895.     break;}
  896. case 36:
  897. #line 338 "expread.y"
  898. { write_exp_elt_opcode (BINOP_NOTEQUAL); ;
  899.     break;}
  900. case 37:
  901. #line 342 "expread.y"
  902. { write_exp_elt_opcode (BINOP_LEQ); ;
  903.     break;}
  904. case 38:
  905. #line 346 "expread.y"
  906. { write_exp_elt_opcode (BINOP_GEQ); ;
  907.     break;}
  908. case 39:
  909. #line 350 "expread.y"
  910. { write_exp_elt_opcode (BINOP_LESS); ;
  911.     break;}
  912. case 40:
  913. #line 354 "expread.y"
  914. { write_exp_elt_opcode (BINOP_GTR); ;
  915.     break;}
  916. case 41:
  917. #line 358 "expread.y"
  918. { write_exp_elt_opcode (BINOP_LOGAND); ;
  919.     break;}
  920. case 42:
  921. #line 362 "expread.y"
  922. { write_exp_elt_opcode (BINOP_LOGXOR); ;
  923.     break;}
  924. case 43:
  925. #line 366 "expread.y"
  926. { write_exp_elt_opcode (BINOP_LOGIOR); ;
  927.     break;}
  928. case 44:
  929. #line 370 "expread.y"
  930. { write_exp_elt_opcode (BINOP_AND); ;
  931.     break;}
  932. case 45:
  933. #line 374 "expread.y"
  934. { write_exp_elt_opcode (BINOP_OR); ;
  935.     break;}
  936. case 46:
  937. #line 378 "expread.y"
  938. { write_exp_elt_opcode (TERNOP_COND); ;
  939.     break;}
  940. case 47:
  941. #line 382 "expread.y"
  942. { write_exp_elt_opcode (BINOP_ASSIGN); ;
  943.     break;}
  944. case 48:
  945. #line 386 "expread.y"
  946. { write_exp_elt_opcode (BINOP_ASSIGN_MODIFY);
  947.               write_exp_elt_opcode (yyvsp[-1].opcode);
  948.               write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); ;
  949.     break;}
  950. case 49:
  951. #line 392 "expread.y"
  952. { write_exp_elt_opcode (OP_LONG);
  953.               if (yyvsp[0].lval == (int) yyvsp[0].lval || yyvsp[0].lval == (unsigned int) yyvsp[0].lval)
  954.                 write_exp_elt_type (builtin_type_int);
  955.               else
  956.                 write_exp_elt_type (BUILTIN_TYPE_LONGEST);
  957.               write_exp_elt_longcst ((LONGEST) yyvsp[0].lval);
  958.               write_exp_elt_opcode (OP_LONG); ;
  959.     break;}
  960. case 50:
  961. #line 402 "expread.y"
  962. {
  963.               write_exp_elt_opcode (OP_LONG);
  964.               if (yyvsp[0].ulval == (unsigned int) yyvsp[0].ulval)
  965.                 write_exp_elt_type (builtin_type_unsigned_int);
  966.               else
  967.                 write_exp_elt_type (BUILTIN_TYPE_UNSIGNED_LONGEST);
  968.               write_exp_elt_longcst ((LONGEST) yyvsp[0].ulval);
  969.               write_exp_elt_opcode (OP_LONG);
  970.             ;
  971.     break;}
  972. case 51:
  973. #line 414 "expread.y"
  974. { write_exp_elt_opcode (OP_LONG);
  975.               write_exp_elt_type (builtin_type_char);
  976.               write_exp_elt_longcst ((LONGEST) yyvsp[0].lval);
  977.               write_exp_elt_opcode (OP_LONG); ;
  978.     break;}
  979. case 52:
  980. #line 421 "expread.y"
  981. { write_exp_elt_opcode (OP_DOUBLE);
  982.               write_exp_elt_type (builtin_type_double);
  983.               write_exp_elt_dblcst (yyvsp[0].dval);
  984.               write_exp_elt_opcode (OP_DOUBLE); ;
  985.     break;}
  986. case 54:
  987. #line 431 "expread.y"
  988. { write_exp_elt_opcode (OP_LAST);
  989.               write_exp_elt_longcst ((LONGEST) yyvsp[0].lval);
  990.               write_exp_elt_opcode (OP_LAST); ;
  991.     break;}
  992. case 55:
  993. #line 437 "expread.y"
  994. { write_exp_elt_opcode (OP_REGISTER);
  995.               write_exp_elt_longcst ((LONGEST) yyvsp[0].lval);
  996.               write_exp_elt_opcode (OP_REGISTER); ;
  997.     break;}
  998. case 56:
  999. #line 443 "expread.y"
  1000. { write_exp_elt_opcode (OP_INTERNALVAR);
  1001.               write_exp_elt_intern (yyvsp[0].ivar);
  1002.               write_exp_elt_opcode (OP_INTERNALVAR); ;
  1003.     break;}
  1004. case 57:
  1005. #line 449 "expread.y"
  1006. { write_exp_elt_opcode (OP_LONG);
  1007.               write_exp_elt_type (builtin_type_int);
  1008.               write_exp_elt_longcst ((LONGEST) TYPE_LENGTH (yyvsp[-1].tval));
  1009.               write_exp_elt_opcode (OP_LONG); ;
  1010.     break;}
  1011. case 58:
  1012. #line 456 "expread.y"
  1013. { write_exp_elt_opcode (OP_STRING);
  1014.               write_exp_string (yyvsp[0].sval);
  1015.               write_exp_elt_opcode (OP_STRING); ;
  1016.     break;}
  1017. case 59:
  1018. #line 463 "expread.y"
  1019. { write_exp_elt_opcode (OP_THIS);
  1020.               write_exp_elt_opcode (OP_THIS); ;
  1021.     break;}
  1022. case 60:
  1023. #line 470 "expread.y"
  1024. {
  1025.               struct symtab *tem = lookup_symtab (copy_name (yyvsp[0].sval));
  1026.               struct symbol *sym;
  1027.               
  1028.               if (tem)
  1029.                 yyval.bval = BLOCKVECTOR_BLOCK (BLOCKVECTOR (tem), 1);
  1030.               else
  1031.                 {
  1032.                   sym = lookup_symbol (copy_name (yyvsp[0].sval),
  1033.                            expression_context_block,
  1034.                            VAR_NAMESPACE, 0);
  1035.                   if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
  1036.                 yyval.bval = SYMBOL_BLOCK_VALUE (sym);
  1037.                   else
  1038.                 error ("No file or function \"%s\".",
  1039.                        copy_name (yyvsp[0].sval));
  1040.                 }
  1041.             ;
  1042.     break;}
  1043. case 61:
  1044. #line 491 "expread.y"
  1045. { struct symbol *tem
  1046.                 = lookup_symbol (copy_name (yyvsp[0].sval), yyvsp[-2].bval, VAR_NAMESPACE, 0);
  1047.               if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
  1048.                 error ("No function \"%s\" in specified context.",
  1049.                    copy_name (yyvsp[0].sval));
  1050.               yyval.bval = SYMBOL_BLOCK_VALUE (tem); ;
  1051.     break;}
  1052. case 62:
  1053. #line 500 "expread.y"
  1054. { struct symbol *sym;
  1055.               sym = lookup_symbol (copy_name (yyvsp[0].sval), yyvsp[-2].bval, VAR_NAMESPACE, 0);
  1056.               if (sym == 0)
  1057.                 error ("No symbol \"%s\" in specified context.",
  1058.                    copy_name (yyvsp[0].sval));
  1059.               write_exp_elt_opcode (OP_VAR_VALUE);
  1060.               write_exp_elt_sym (sym);
  1061.               write_exp_elt_opcode (OP_VAR_VALUE); ;
  1062.     break;}
  1063. case 63:
  1064. #line 511 "expread.y"
  1065. {
  1066.               struct type *type = yyvsp[-2].tval;
  1067.               if (TYPE_CODE (type) != TYPE_CODE_STRUCT
  1068.                   && TYPE_CODE (type) != TYPE_CODE_UNION)
  1069.                 error ("`%s' is not defined as an aggregate type.",
  1070.                    TYPE_NAME (type));
  1071.  
  1072.               write_exp_elt_opcode (OP_SCOPE);
  1073.               write_exp_elt_type (type);
  1074.               write_exp_string (yyvsp[0].sval);
  1075.               write_exp_elt_opcode (OP_SCOPE);
  1076.             ;
  1077.     break;}
  1078. case 64:
  1079. #line 524 "expread.y"
  1080. {
  1081.               char *name = copy_name (yyvsp[0].sval);
  1082.               struct symbol *sym;
  1083.               int i;
  1084.  
  1085.               sym = lookup_symbol (name, 0, VAR_NAMESPACE, 0);
  1086.               if (sym)
  1087.                 {
  1088.                   write_exp_elt_opcode (OP_VAR_VALUE);
  1089.                   write_exp_elt_sym (sym);
  1090.                   write_exp_elt_opcode (OP_VAR_VALUE);
  1091.                   break;
  1092.                 }
  1093.               for (i = 0; i < misc_function_count; i++)
  1094.                 if (!strcmp (misc_function_vector[i].name, name))
  1095.                   break;
  1096.  
  1097.               if (i < misc_function_count)
  1098.                 {
  1099.                   enum misc_function_type mft =
  1100.                 (enum misc_function_type)
  1101.                   misc_function_vector[i].type;
  1102.                   
  1103.                   write_exp_elt_opcode (OP_LONG);
  1104.                   write_exp_elt_type (builtin_type_int);
  1105.                   write_exp_elt_longcst ((LONGEST) misc_function_vector[i].address);
  1106.                   write_exp_elt_opcode (OP_LONG);
  1107.                   write_exp_elt_opcode (UNOP_MEMVAL);
  1108.                   if (mft == mf_data || mft == mf_bss)
  1109.                 write_exp_elt_type (builtin_type_int);
  1110.                   else if (mft == mf_text)
  1111.                 write_exp_elt_type (lookup_function_type (builtin_type_int));
  1112.                   else
  1113.                 write_exp_elt_type (builtin_type_char);
  1114.                   write_exp_elt_opcode (UNOP_MEMVAL);
  1115.                 }
  1116.               else
  1117.                 if (symtab_list == 0
  1118.                 && partial_symtab_list == 0)
  1119.                   error ("No symbol table is loaded.  Use the \"symbol-file\" command.");
  1120.                 else
  1121.                   error ("No symbol \"%s\" in current context.", name);
  1122.             ;
  1123.     break;}
  1124. case 65:
  1125. #line 570 "expread.y"
  1126. { struct symbol *sym;
  1127.               int is_a_field_of_this;
  1128.  
  1129.               sym = lookup_symbol (copy_name (yyvsp[0].sval),
  1130.                            expression_context_block,
  1131.                            VAR_NAMESPACE,
  1132.                            &is_a_field_of_this);
  1133.               if (sym)
  1134.                 {
  1135.                   switch (sym->class)
  1136.                 {
  1137.                 case LOC_REGISTER:
  1138.                 case LOC_ARG:
  1139.                 case LOC_LOCAL:
  1140.                   if (innermost_block == 0 ||
  1141.                       contained_in (block_found, 
  1142.                             innermost_block))
  1143.                     innermost_block = block_found;
  1144.                 }
  1145.                   write_exp_elt_opcode (OP_VAR_VALUE);
  1146.                   write_exp_elt_sym (sym);
  1147.                   write_exp_elt_opcode (OP_VAR_VALUE);
  1148.                 }
  1149.               else if (is_a_field_of_this)
  1150.                 {
  1151.                   /* C++: it hangs off of `this'.  Must
  1152.                      not inadvertently convert from a method call
  1153.                  to data ref.  */
  1154.                   if (innermost_block == 0 || 
  1155.                   contained_in (block_found, innermost_block))
  1156.                 innermost_block = block_found;
  1157.                   write_exp_elt_opcode (OP_THIS);
  1158.                   write_exp_elt_opcode (OP_THIS);
  1159.                   write_exp_elt_opcode (STRUCTOP_PTR);
  1160.                   write_exp_string (yyvsp[0].sval);
  1161.                   write_exp_elt_opcode (STRUCTOP_PTR);
  1162.                 }
  1163.               else
  1164.                 {
  1165.                   register int i;
  1166.                   register char *arg = copy_name (yyvsp[0].sval);
  1167.  
  1168.                   for (i = 0; i < misc_function_count; i++)
  1169.                 if (!strcmp (misc_function_vector[i].name, arg))
  1170.                   break;
  1171.  
  1172.                   if (i < misc_function_count)
  1173.                 {
  1174.                   enum misc_function_type mft =
  1175.                     (enum misc_function_type)
  1176.                       misc_function_vector[i].type;
  1177.                   
  1178.                   write_exp_elt_opcode (OP_LONG);
  1179.                   write_exp_elt_type (builtin_type_int);
  1180.                   write_exp_elt_longcst ((LONGEST) misc_function_vector[i].address);
  1181.                   write_exp_elt_opcode (OP_LONG);
  1182.                   write_exp_elt_opcode (UNOP_MEMVAL);
  1183.                   if (mft == mf_data || mft == mf_bss)
  1184.                     write_exp_elt_type (builtin_type_int);
  1185.                   else if (mft == mf_text)
  1186.                     write_exp_elt_type (lookup_function_type (builtin_type_int));
  1187.                   else
  1188.                     write_exp_elt_type (builtin_type_char);
  1189.                   write_exp_elt_opcode (UNOP_MEMVAL);
  1190.                 }
  1191.                   else if (symtab_list == 0
  1192.                        && partial_symtab_list == 0)
  1193.                 error ("No symbol table is loaded.  Use the \"symbol-file\" command.");
  1194.                   else
  1195.                 error ("No symbol \"%s\" in current context.",
  1196.                        copy_name (yyvsp[0].sval));
  1197.                 }
  1198.             ;
  1199.     break;}
  1200. case 67:
  1201. #line 648 "expread.y"
  1202. {
  1203.           /* This is where the interesting stuff happens.  */
  1204.           int done = 0;
  1205.           int array_size;
  1206.           struct type *follow_type = yyvsp[-1].tval;
  1207.           
  1208.           while (!done)
  1209.             switch (pop_type ())
  1210.               {
  1211.               case tp_end:
  1212.             done = 1;
  1213.             break;
  1214.               case tp_pointer:
  1215.             follow_type = lookup_pointer_type (follow_type);
  1216.             break;
  1217.               case tp_reference:
  1218.             follow_type = lookup_reference_type (follow_type);
  1219.             break;
  1220.               case tp_array:
  1221.             array_size = (int) pop_type ();
  1222.             if (array_size != -1)
  1223.               follow_type = create_array_type (follow_type,
  1224.                                array_size);
  1225.             else
  1226.               follow_type = lookup_pointer_type (follow_type);
  1227.             break;
  1228.               case tp_function:
  1229.             follow_type = lookup_function_type (follow_type);
  1230.             break;
  1231.               }
  1232.           yyval.tval = follow_type;
  1233.         ;
  1234.     break;}
  1235. case 68:
  1236. #line 683 "expread.y"
  1237. { push_type (tp_pointer); yyval.voidval = 0; ;
  1238.     break;}
  1239. case 69:
  1240. #line 685 "expread.y"
  1241. { push_type (tp_pointer); yyval.voidval = yyvsp[0].voidval; ;
  1242.     break;}
  1243. case 71:
  1244. #line 690 "expread.y"
  1245. { yyval.voidval = yyvsp[-1].voidval; ;
  1246.     break;}
  1247. case 72:
  1248. #line 692 "expread.y"
  1249. {
  1250.               push_type ((enum type_pieces) yyvsp[0].lval);
  1251.               push_type (tp_array);
  1252.             ;
  1253.     break;}
  1254. case 73:
  1255. #line 697 "expread.y"
  1256. {
  1257.               push_type ((enum type_pieces) yyvsp[0].lval);
  1258.               push_type (tp_array);
  1259.               yyval.voidval = 0;
  1260.             ;
  1261.     break;}
  1262. case 74:
  1263. #line 703 "expread.y"
  1264. { push_type (tp_function); ;
  1265.     break;}
  1266. case 75:
  1267. #line 705 "expread.y"
  1268. { push_type (tp_function); ;
  1269.     break;}
  1270. case 76:
  1271. #line 709 "expread.y"
  1272. { yyval.lval = -1; ;
  1273.     break;}
  1274. case 77:
  1275. #line 711 "expread.y"
  1276. { yyval.lval = yyvsp[-1].lval; ;
  1277.     break;}
  1278. case 78:
  1279. #line 715 "expread.y"
  1280. { yyval.voidval = 0; ;
  1281.     break;}
  1282. case 80:
  1283. #line 720 "expread.y"
  1284. { yyval.tval = lookup_member_type (builtin_type_int, yyvsp[-2].tval); ;
  1285.     break;}
  1286. case 81:
  1287. #line 722 "expread.y"
  1288. { yyval.tval = lookup_member_type (yyvsp[-5].tval, yyvsp[-3].tval); ;
  1289.     break;}
  1290. case 82:
  1291. #line 724 "expread.y"
  1292. { yyval.tval = lookup_member_type
  1293.                 (lookup_function_type (yyvsp[-7].tval), yyvsp[-5].tval); ;
  1294.     break;}
  1295. case 83:
  1296. #line 727 "expread.y"
  1297. { yyval.tval = lookup_member_type
  1298.                 (lookup_function_type (yyvsp[-8].tval), yyvsp[-6].tval);
  1299.               free (yyvsp[-1].tvec); ;
  1300.     break;}
  1301. case 84:
  1302. #line 734 "expread.y"
  1303. { yyval.tval = lookup_typename (copy_name (yyvsp[0].sval),
  1304.                         expression_context_block, 0); ;
  1305.     break;}
  1306. case 85:
  1307. #line 737 "expread.y"
  1308. { yyval.tval = builtin_type_int; ;
  1309.     break;}
  1310. case 86:
  1311. #line 739 "expread.y"
  1312. { yyval.tval = builtin_type_long; ;
  1313.     break;}
  1314. case 87:
  1315. #line 741 "expread.y"
  1316. { yyval.tval = builtin_type_short; ;
  1317.     break;}
  1318. case 88:
  1319. #line 743 "expread.y"
  1320. { yyval.tval = builtin_type_long; ;
  1321.     break;}
  1322. case 89:
  1323. #line 745 "expread.y"
  1324. { yyval.tval = builtin_type_unsigned_long; ;
  1325.     break;}
  1326. case 90:
  1327. #line 747 "expread.y"
  1328. { yyval.tval = builtin_type_short; ;
  1329.     break;}
  1330. case 91:
  1331. #line 749 "expread.y"
  1332. { yyval.tval = builtin_type_unsigned_short; ;
  1333.     break;}
  1334. case 92:
  1335. #line 751 "expread.y"
  1336. { yyval.tval = lookup_struct (copy_name (yyvsp[0].sval),
  1337.                           expression_context_block); ;
  1338.     break;}
  1339. case 93:
  1340. #line 754 "expread.y"
  1341. { yyval.tval = lookup_union (copy_name (yyvsp[0].sval),
  1342.                          expression_context_block); ;
  1343.     break;}
  1344. case 94:
  1345. #line 757 "expread.y"
  1346. { yyval.tval = lookup_enum (copy_name (yyvsp[0].sval),
  1347.                         expression_context_block); ;
  1348.     break;}
  1349. case 95:
  1350. #line 760 "expread.y"
  1351. { yyval.tval = lookup_unsigned_typename (copy_name (yyvsp[0].sval)); ;
  1352.     break;}
  1353. case 96:
  1354. #line 762 "expread.y"
  1355. { yyval.tval = builtin_type_unsigned_int; ;
  1356.     break;}
  1357. case 97:
  1358. #line 764 "expread.y"
  1359. { yyval.tval = lookup_typename (copy_name (yyvsp[0].sval),
  1360.                         expression_context_block, 0); ;
  1361.     break;}
  1362. case 98:
  1363. #line 767 "expread.y"
  1364. { yyval.tval = builtin_type_int; ;
  1365.     break;}
  1366. case 100:
  1367. #line 772 "expread.y"
  1368. {
  1369.           yyval.sval.ptr = "int";
  1370.           yyval.sval.length = 3;
  1371.         ;
  1372.     break;}
  1373. case 101:
  1374. #line 777 "expread.y"
  1375. {
  1376.           yyval.sval.ptr = "long";
  1377.           yyval.sval.length = 4;
  1378.         ;
  1379.     break;}
  1380. case 102:
  1381. #line 782 "expread.y"
  1382. {
  1383.           yyval.sval.ptr = "short";
  1384.           yyval.sval.length = 5;
  1385.         ;
  1386.     break;}
  1387. case 103:
  1388. #line 790 "expread.y"
  1389. { yyval.tvec = (struct type **)xmalloc (sizeof (struct type *) * 2);
  1390.           yyval.tvec[0] = (struct type *)0;
  1391.           yyval.tvec[1] = yyvsp[0].tval;
  1392.         ;
  1393.     break;}
  1394. case 104:
  1395. #line 795 "expread.y"
  1396. { int len = sizeof (struct type *) * ++(yyvsp[-2].ivec[0]);
  1397.           yyval.tvec = (struct type **)xrealloc (yyvsp[-2].tvec, len);
  1398.           yyval.tvec[yyval.ivec[0]] = yyvsp[0].tval;
  1399.         ;
  1400.     break;}
  1401. }
  1402.    /* the action file gets copied in in place of this dollarsign */
  1403. #line 327 "bison.simple"
  1404.  
  1405.   yyvsp -= yylen;
  1406.   yyssp -= yylen;
  1407. #ifdef YYLSP_NEEDED
  1408.   yylsp -= yylen;
  1409. #endif
  1410.  
  1411. #if YYDEBUG != 0
  1412.   if (yydebug)
  1413.     {
  1414.       short *ssp1 = yyss - 1;
  1415.       fprintf (stderr, "state stack now");
  1416.       while (ssp1 != yyssp)
  1417.     fprintf (stderr, " %d", *++ssp1);
  1418.       fprintf (stderr, "\n");
  1419.     }
  1420. #endif
  1421.  
  1422.   *++yyvsp = yyval;
  1423.  
  1424. #ifdef YYLSP_NEEDED
  1425.   yylsp++;
  1426.   if (yylen == 0)
  1427.     {
  1428.       yylsp->first_line = yylloc.first_line;
  1429.       yylsp->first_column = yylloc.first_column;
  1430.       yylsp->last_line = (yylsp-1)->last_line;
  1431.       yylsp->last_column = (yylsp-1)->last_column;
  1432.       yylsp->text = 0;
  1433.     }
  1434.   else
  1435.     {
  1436.       yylsp->last_line = (yylsp+yylen-1)->last_line;
  1437.       yylsp->last_column = (yylsp+yylen-1)->last_column;
  1438.     }
  1439. #endif
  1440.  
  1441.   /* Now "shift" the result of the reduction.
  1442.      Determine what state that goes to,
  1443.      based on the state we popped back to
  1444.      and the rule number reduced by.  */
  1445.  
  1446.   yyn = yyr1[yyn];
  1447.  
  1448.   yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
  1449.   if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
  1450.     yystate = yytable[yystate];
  1451.   else
  1452.     yystate = yydefgoto[yyn - YYNTBASE];
  1453.  
  1454.   goto yynewstate;
  1455.  
  1456. yyerrlab:   /* here on detecting error */
  1457.  
  1458.   if (! yyerrstatus)
  1459.     /* If not already recovering from an error, report this error.  */
  1460.     {
  1461.       ++yynerrs;
  1462.       yyerror("parse error");
  1463.     }
  1464.  
  1465.   if (yyerrstatus == 3)
  1466.     {
  1467.       /* if just tried and failed to reuse lookahead token after an error, discard it.  */
  1468.  
  1469.       /* return failure if at end of input */
  1470.       if (yychar == YYEOF)
  1471.     YYABORT;
  1472.  
  1473. #if YYDEBUG != 0
  1474.       if (yydebug)
  1475.     fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
  1476. #endif
  1477.  
  1478.       yychar = YYEMPTY;
  1479.     }
  1480.  
  1481.   /* Else will try to reuse lookahead token
  1482.      after shifting the error token.  */
  1483.  
  1484.   yyerrstatus = 3;        /* Each real token shifted decrements this */
  1485.  
  1486.   goto yyerrhandle;
  1487.  
  1488. yyerrdefault:  /* current state does not do anything special for the error token. */
  1489.  
  1490. #if 0
  1491.   /* This is wrong; only states that explicitly want error tokens
  1492.      should shift them.  */
  1493.   yyn = yydefact[yystate];  /* If its default is to accept any token, ok.  Otherwise pop it.*/
  1494.   if (yyn) goto yydefault;
  1495. #endif
  1496.  
  1497. yyerrpop:   /* pop the current state because it cannot handle the error token */
  1498.  
  1499.   if (yyssp == yyss) YYABORT;
  1500.   yyvsp--;
  1501.   yystate = *--yyssp;
  1502. #ifdef YYLSP_NEEDED
  1503.   yylsp--;
  1504. #endif
  1505.  
  1506. #if YYDEBUG != 0
  1507.   if (yydebug)
  1508.     {
  1509.       short *ssp1 = yyss - 1;
  1510.       fprintf (stderr, "Error: state stack now");
  1511.       while (ssp1 != yyssp)
  1512.     fprintf (stderr, " %d", *++ssp1);
  1513.       fprintf (stderr, "\n");
  1514.     }
  1515. #endif
  1516.  
  1517. yyerrhandle:
  1518.  
  1519.   yyn = yypact[yystate];
  1520.   if (yyn == YYFLAG)
  1521.     goto yyerrdefault;
  1522.  
  1523.   yyn += YYTERROR;
  1524.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
  1525.     goto yyerrdefault;
  1526.  
  1527.   yyn = yytable[yyn];
  1528.   if (yyn < 0)
  1529.     {
  1530.       if (yyn == YYFLAG)
  1531.     goto yyerrpop;
  1532.       yyn = -yyn;
  1533.       goto yyreduce;
  1534.     }
  1535.   else if (yyn == 0)
  1536.     goto yyerrpop;
  1537.  
  1538.   if (yyn == YYFINAL)
  1539.     YYACCEPT;
  1540.  
  1541. #if YYDEBUG != 0
  1542.   if (yydebug)
  1543.     fprintf(stderr, "Shifting error token, ");
  1544. #endif
  1545.  
  1546.   *++yyvsp = yylval;
  1547. #ifdef YYLSP_NEEDED
  1548.   *++yylsp = yylloc;
  1549. #endif
  1550.  
  1551.   yystate = yyn;
  1552.   goto yynewstate;
  1553. }
  1554. #line 810 "expread.y"
  1555.  
  1556.  
  1557. /* Begin counting arguments for a function call,
  1558.    saving the data about any containing call.  */
  1559.  
  1560. static void
  1561. start_arglist ()
  1562. {
  1563.   register struct funcall *new = (struct funcall *) xmalloc (sizeof (struct funcall));
  1564.  
  1565.   new->next = funcall_chain;
  1566.   new->arglist_len = arglist_len;
  1567.   arglist_len = 0;
  1568.   funcall_chain = new;
  1569. }
  1570.  
  1571. /* Return the number of arguments in a function call just terminated,
  1572.    and restore the data for the containing function call.  */
  1573.  
  1574. static int
  1575. end_arglist ()
  1576. {
  1577.   register int val = arglist_len;
  1578.   register struct funcall *call = funcall_chain;
  1579.   funcall_chain = call->next;
  1580.   arglist_len = call->arglist_len;
  1581.   free (call);
  1582.   return val;
  1583. }
  1584.  
  1585. /* Free everything in the funcall chain.
  1586.    Used when there is an error inside parsing.  */
  1587.  
  1588. static void
  1589. free_funcalls ()
  1590. {
  1591.   register struct funcall *call, *next;
  1592.  
  1593.   for (call = funcall_chain; call; call = next)
  1594.     {
  1595.       next = call->next;
  1596.       free (call);
  1597.     }
  1598. }
  1599.  
  1600. /* This page contains the functions for adding data to the  struct expression
  1601.    being constructed.  */
  1602.  
  1603. /* Add one element to the end of the expression.  */
  1604.  
  1605. /* To avoid a bug in the Sun 4 compiler, we pass things that can fit into
  1606.    a register through here */
  1607.  
  1608. static void
  1609. write_exp_elt (expelt)
  1610.      union exp_element expelt;
  1611. {
  1612.   if (expout_ptr >= expout_size)
  1613.     {
  1614.       expout_size *= 2;
  1615.       expout = (struct expression *) xrealloc (expout,
  1616.                            sizeof (struct expression)
  1617.                            + expout_size * sizeof (union exp_element));
  1618.     }
  1619.   expout->elts[expout_ptr++] = expelt;
  1620. }
  1621.  
  1622. static void
  1623. write_exp_elt_opcode (expelt)
  1624.      enum exp_opcode expelt;
  1625. {
  1626.   union exp_element tmp;
  1627.  
  1628.   tmp.opcode = expelt;
  1629.  
  1630.   write_exp_elt (tmp);
  1631. }
  1632.  
  1633. static void
  1634. write_exp_elt_sym (expelt)
  1635.      struct symbol *expelt;
  1636. {
  1637.   union exp_element tmp;
  1638.  
  1639.   tmp.symbol = expelt;
  1640.  
  1641.   write_exp_elt (tmp);
  1642. }
  1643.  
  1644. static void
  1645. write_exp_elt_longcst (expelt)
  1646.      LONGEST expelt;
  1647. {
  1648.   union exp_element tmp;
  1649.  
  1650.   tmp.longconst = expelt;
  1651.  
  1652.   write_exp_elt (tmp);
  1653. }
  1654.  
  1655. static void
  1656. write_exp_elt_dblcst (expelt)
  1657.      double expelt;
  1658. {
  1659.   union exp_element tmp;
  1660.  
  1661.   tmp.doubleconst = expelt;
  1662.  
  1663.   write_exp_elt (tmp);
  1664. }
  1665.  
  1666. static void
  1667. write_exp_elt_type (expelt)
  1668.      struct type *expelt;
  1669. {
  1670.   union exp_element tmp;
  1671.  
  1672.   tmp.type = expelt;
  1673.  
  1674.   write_exp_elt (tmp);
  1675. }
  1676.  
  1677. static void
  1678. write_exp_elt_intern (expelt)
  1679.      struct internalvar *expelt;
  1680. {
  1681.   union exp_element tmp;
  1682.  
  1683.   tmp.internalvar = expelt;
  1684.  
  1685.   write_exp_elt (tmp);
  1686. }
  1687.  
  1688. /* Add a string constant to the end of the expression.
  1689.    Follow it by its length in bytes, as a separate exp_element.  */
  1690.  
  1691. static void
  1692. write_exp_string (str)
  1693.      struct stoken str;
  1694. {
  1695.   register int len = str.length;
  1696.   register int lenelt
  1697.     = (len + sizeof (union exp_element)) / sizeof (union exp_element);
  1698.  
  1699.   expout_ptr += lenelt;
  1700.  
  1701.   if (expout_ptr >= expout_size)
  1702.     {
  1703.       expout_size = max (expout_size * 2, expout_ptr + 10);
  1704.       expout = (struct expression *)
  1705.     xrealloc (expout, (sizeof (struct expression)
  1706.                + (expout_size * sizeof (union exp_element))));
  1707.     }
  1708.   bcopy (str.ptr, (char *) &expout->elts[expout_ptr - lenelt], len);
  1709.   ((char *) &expout->elts[expout_ptr - lenelt])[len] = 0;
  1710.   write_exp_elt_longcst ((LONGEST) len);
  1711. }
  1712.  
  1713. /* During parsing of a C expression, the pointer to the next character
  1714.    is in this variable.  */
  1715.  
  1716. static char *lexptr;
  1717.  
  1718. /* Tokens that refer to names do so with explicit pointer and length,
  1719.    so they can share the storage that lexptr is parsing.
  1720.  
  1721.    When it is necessary to pass a name to a function that expects
  1722.    a null-terminated string, the substring is copied out
  1723.    into a block of storage that namecopy points to.
  1724.  
  1725.    namecopy is allocated once, guaranteed big enough, for each parsing.  */
  1726.  
  1727. static char *namecopy;
  1728.  
  1729. /* Current depth in parentheses within the expression.  */
  1730.  
  1731. static int paren_depth;
  1732.  
  1733. /* Nonzero means stop parsing on first comma (if not within parentheses).  */
  1734.  
  1735. static int comma_terminates;
  1736.  
  1737. /* Take care of parsing a number (anything that starts with a digit).
  1738.    Set yylval and return the token type; update lexptr.
  1739.    LEN is the number of characters in it.  */
  1740.  
  1741. /*** Needs some error checking for the float case ***/
  1742.  
  1743. static int
  1744. parse_number (olen)
  1745.      int olen;
  1746. {
  1747.   register char *p = lexptr;
  1748.   register LONGEST n = 0;
  1749.   register int c;
  1750.   register int base = 10;
  1751.   register int len = olen;
  1752.   char *err_copy;
  1753.   int unsigned_p = 0;
  1754.  
  1755.   extern double atof ();
  1756.  
  1757.   for (c = 0; c < len; c++)
  1758.     if (p[c] == '.')
  1759.       {
  1760.     /* It's a float since it contains a point.  */
  1761.     yylval.dval = atof (p);
  1762.     lexptr += len;
  1763.     return FLOAT;
  1764.       }
  1765.  
  1766.   if (len >= 3 && (!strncmp (p, "0x", 2) || !strncmp (p, "0X", 2)))
  1767.     {
  1768.       p += 2;
  1769.       base = 16;
  1770.       len -= 2;
  1771.     }
  1772.   else if (*p == '0')
  1773.     base = 8;
  1774.  
  1775.   while (len-- > 0)
  1776.     {
  1777.       c = *p++;
  1778.       if (c >= 'A' && c <= 'Z') c += 'a' - 'A';
  1779.       if (c != 'l' && c != 'u')
  1780.     n *= base;
  1781.       if (c >= '0' && c <= '9')
  1782.     n += c - '0';
  1783.       else
  1784.     {
  1785.       if (base == 16 && c >= 'a' && c <= 'f')
  1786.         n += c - 'a' + 10;
  1787.       else if (len == 0 && c == 'l')
  1788.         ;
  1789.       else if (len == 0 && c == 'u')
  1790.         unsigned_p = 1;
  1791.       else if (base == 10 && len != 0 && (c == 'e' || c == 'E'))
  1792.         {
  1793.           /* Scientific notation, where we are unlucky enough not
  1794.          to have a '.' in the string.  */
  1795.           yylval.dval = atof (lexptr);
  1796.           lexptr += olen;
  1797.           return FLOAT;
  1798.         }
  1799.       else
  1800.         {
  1801.           err_copy = (char *) alloca (olen + 1);
  1802.           bcopy (lexptr, err_copy, olen);
  1803.           err_copy[olen] = 0;
  1804.           error ("Invalid number \"%s\".", err_copy);
  1805.         }
  1806.     }
  1807.     }
  1808.  
  1809.   lexptr = p;
  1810.   if (unsigned_p)
  1811.     {
  1812.       yylval.ulval = n;
  1813.       return UINT;
  1814.     }
  1815.   else
  1816.     {
  1817.       yylval.lval = n;
  1818.       return INT;
  1819.     }
  1820. }
  1821.  
  1822. struct token
  1823. {
  1824.   char *operator;
  1825.   int token;
  1826.   enum exp_opcode opcode;
  1827. };
  1828.  
  1829. static struct token tokentab3[] =
  1830.   {
  1831.     {">>=", ASSIGN_MODIFY, BINOP_RSH},
  1832.     {"<<=", ASSIGN_MODIFY, BINOP_LSH}
  1833.   };
  1834.  
  1835. static struct token tokentab2[] =
  1836.   {
  1837.     {"+=", ASSIGN_MODIFY, BINOP_ADD},
  1838.     {"-=", ASSIGN_MODIFY, BINOP_SUB},
  1839.     {"*=", ASSIGN_MODIFY, BINOP_MUL},
  1840.     {"/=", ASSIGN_MODIFY, BINOP_DIV},
  1841.     {"%=", ASSIGN_MODIFY, BINOP_REM},
  1842.     {"|=", ASSIGN_MODIFY, BINOP_LOGIOR},
  1843.     {"&=", ASSIGN_MODIFY, BINOP_LOGAND},
  1844.     {"^=", ASSIGN_MODIFY, BINOP_LOGXOR},
  1845.     {"++", INCREMENT, BINOP_END},
  1846.     {"--", DECREMENT, BINOP_END},
  1847.     {"->", ARROW, BINOP_END},
  1848.     {"&&", AND, BINOP_END},
  1849.     {"||", OR, BINOP_END},
  1850.     {"::", COLONCOLON, BINOP_END},
  1851.     {"<<", LSH, BINOP_END},
  1852.     {">>", RSH, BINOP_END},
  1853.     {"==", EQUAL, BINOP_END},
  1854.     {"!=", NOTEQUAL, BINOP_END},
  1855.     {"<=", LEQ, BINOP_END},
  1856.     {">=", GEQ, BINOP_END}
  1857.   };
  1858.  
  1859. /* assign machine-independent names to certain registers 
  1860.  * (unless overridden by the REGISTER_NAMES table)
  1861.  */
  1862. struct std_regs {
  1863.     char *name;
  1864.     int regnum;
  1865. } std_regs[] = {
  1866. #ifdef PC_REGNUM
  1867.     { "pc", PC_REGNUM },
  1868. #endif
  1869. #ifdef FP_REGNUM
  1870.     { "fp", FP_REGNUM },
  1871. #endif
  1872. #ifdef SP_REGNUM
  1873.     { "sp", SP_REGNUM },
  1874. #endif
  1875. #ifdef PS_REGNUM
  1876.     { "ps", PS_REGNUM },
  1877. #endif
  1878. };
  1879.  
  1880. #define NUM_STD_REGS (sizeof std_regs / sizeof std_regs[0])
  1881.  
  1882. /* Read one token, getting characters through lexptr.  */
  1883.  
  1884. static int
  1885. yylex ()
  1886. {
  1887.   register int c;
  1888.   register int namelen;
  1889.   register int i;
  1890.   register char *tokstart;
  1891.  
  1892.  retry:
  1893.  
  1894.   tokstart = lexptr;
  1895.   /* See if it is a special token of length 3.  */
  1896.   for (i = 0; i < sizeof tokentab3 / sizeof tokentab3[0]; i++)
  1897.     if (!strncmp (tokstart, tokentab3[i].operator, 3))
  1898.       {
  1899.     lexptr += 3;
  1900.     yylval.opcode = tokentab3[i].opcode;
  1901.     return tokentab3[i].token;
  1902.       }
  1903.  
  1904.   /* See if it is a special token of length 2.  */
  1905.   for (i = 0; i < sizeof tokentab2 / sizeof tokentab2[0]; i++)
  1906.     if (!strncmp (tokstart, tokentab2[i].operator, 2))
  1907.       {
  1908.     lexptr += 2;
  1909.     yylval.opcode = tokentab2[i].opcode;
  1910.     return tokentab2[i].token;
  1911.       }
  1912.  
  1913.   switch (c = *tokstart)
  1914.     {
  1915.     case 0:
  1916.       return 0;
  1917.  
  1918.     case ' ':
  1919.     case '\t':
  1920.     case '\n':
  1921.       lexptr++;
  1922.       goto retry;
  1923.  
  1924.     case '\'':
  1925.       lexptr++;
  1926.       c = *lexptr++;
  1927.       if (c == '\\')
  1928.     c = parse_escape (&lexptr);
  1929.       yylval.lval = c;
  1930.       c = *lexptr++;
  1931.       if (c != '\'')
  1932.     error ("Invalid character constant.");
  1933.       return CHAR;
  1934.  
  1935.     case '(':
  1936.       paren_depth++;
  1937.       lexptr++;
  1938.       return c;
  1939.  
  1940.     case ')':
  1941.       if (paren_depth == 0)
  1942.     return 0;
  1943.       paren_depth--;
  1944.       lexptr++;
  1945.       return c;
  1946.  
  1947.     case ',':
  1948.       if (comma_terminates && paren_depth == 0)
  1949.     return 0;
  1950.       lexptr++;
  1951.       return c;
  1952.  
  1953.     case '.':
  1954.       /* Might be a floating point number.  */
  1955.       if (lexptr[1] >= '0' && lexptr[1] <= '9')
  1956.     break;            /* Falls into number code.  */
  1957.  
  1958.     case '+':
  1959.     case '-':
  1960.     case '*':
  1961.     case '/':
  1962.     case '%':
  1963.     case '|':
  1964.     case '&':
  1965.     case '^':
  1966.     case '~':
  1967.     case '!':
  1968.     case '@':
  1969.     case '<':
  1970.     case '>':
  1971.     case '[':
  1972.     case ']':
  1973.     case '?':
  1974.     case ':':
  1975.     case '=':
  1976.     case '{':
  1977.     case '}':
  1978.       lexptr++;
  1979.       return c;
  1980.  
  1981.     case '"':
  1982.       for (namelen = 1; (c = tokstart[namelen]) != '"'; namelen++)
  1983.     if (c == '\\')
  1984.       {
  1985.         c = tokstart[++namelen];
  1986.         if (c >= '0' && c <= '9')
  1987.           {
  1988.         c = tokstart[++namelen];
  1989.         if (c >= '0' && c <= '9')
  1990.           c = tokstart[++namelen];
  1991.           }
  1992.       }
  1993.       yylval.sval.ptr = tokstart + 1;
  1994.       yylval.sval.length = namelen - 1;
  1995.       lexptr += namelen + 1;
  1996.       return STRING;
  1997.     }
  1998.  
  1999.   /* Is it a number?  */
  2000.   /* Note:  We have already dealt with the case of the token '.'.
  2001.      See case '.' above.  */
  2002.   if ((c >= '0' && c <= '9') || c == '.')
  2003.     {
  2004.       /* It's a number.  */
  2005.       int got_dot = 0, got_e = 0;
  2006.       register char *p = tokstart;
  2007.       int hex = c == '0' && (p[1] == 'x' || p[1] == 'X');
  2008.       if (hex)
  2009.     p += 2;
  2010.       for (;; ++p)
  2011.     {
  2012.       if (!hex && !got_e && (*p == 'e' || *p == 'E'))
  2013.         got_dot = got_e = 1;
  2014.       else if (!hex && !got_dot && *p == '.')
  2015.         got_dot = 1;
  2016.       else if (got_e && (p[-1] == 'e' || p[-1] == 'E')
  2017.            && (*p == '-' || *p == '+'))
  2018.         /* This is the sign of the exponent, not the end of the
  2019.            number.  */
  2020.         continue;
  2021.       else if (*p < '0' || *p > '9'
  2022.            && (!hex || ((*p < 'a' || *p > 'f')
  2023.                 && (*p < 'A' || *p > 'F'))))
  2024.         break;
  2025.     }
  2026.       return parse_number (p - tokstart);
  2027.     }
  2028.  
  2029.   if (!(c == '_' || c == '$'
  2030.     || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
  2031.     /* We must have come across a bad character (e.g. ';').  */
  2032.     error ("Invalid character '%c' in expression.", c);
  2033.  
  2034.   /* It's a name.  See how long it is.  */
  2035.   namelen = 0;
  2036.   for (c = tokstart[namelen];
  2037.        (c == '_' || c == '$' || (c >= '0' && c <= '9')
  2038.     || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'));
  2039.        c = tokstart[++namelen])
  2040.     ;
  2041.  
  2042.   /* The token "if" terminates the expression and is NOT 
  2043.      removed from the input stream.  */
  2044.   if (namelen == 2 && tokstart[0] == 'i' && tokstart[1] == 'f')
  2045.     {
  2046.       return 0;
  2047.     }
  2048.  
  2049.   lexptr += namelen;
  2050.  
  2051.   /* Handle the tokens $digits; also $ (short for $0) and $$ (short for $$1)
  2052.      and $$digits (equivalent to $<-digits> if you could type that).
  2053.      Make token type LAST, and put the number (the digits) in yylval.  */
  2054.  
  2055.   if (*tokstart == '$')
  2056.     {
  2057.       register int negate = 0;
  2058.       c = 1;
  2059.       /* Double dollar means negate the number and add -1 as well.
  2060.      Thus $$ alone means -1.  */
  2061.       if (namelen >= 2 && tokstart[1] == '$')
  2062.     {
  2063.       negate = 1;
  2064.       c = 2;
  2065.     }
  2066.       if (c == namelen)
  2067.     {
  2068.       /* Just dollars (one or two) */
  2069.       yylval.lval = - negate;
  2070.       return LAST;
  2071.     }
  2072.       /* Is the rest of the token digits?  */
  2073.       for (; c < namelen; c++)
  2074.     if (!(tokstart[c] >= '0' && tokstart[c] <= '9'))
  2075.       break;
  2076.       if (c == namelen)
  2077.     {
  2078.       yylval.lval = atoi (tokstart + 1 + negate);
  2079.       if (negate)
  2080.         yylval.lval = - yylval.lval;
  2081.       return LAST;
  2082.     }
  2083.     }
  2084.  
  2085.   /* Handle tokens that refer to machine registers:
  2086.      $ followed by a register name.  */
  2087.  
  2088.   if (*tokstart == '$') {
  2089.     for (c = 0; c < NUM_REGS; c++)
  2090.       if (namelen - 1 == strlen (reg_names[c])
  2091.       && !strncmp (tokstart + 1, reg_names[c], namelen - 1))
  2092.     {
  2093.       yylval.lval = c;
  2094.       return REGNAME;
  2095.     }
  2096.     for (c = 0; c < NUM_STD_REGS; c++)
  2097.      if (namelen - 1 == strlen (std_regs[c].name)
  2098.      && !strncmp (tokstart + 1, std_regs[c].name, namelen - 1))
  2099.        {
  2100.      yylval.lval = std_regs[c].regnum;
  2101.      return REGNAME;
  2102.        }
  2103.   }
  2104.   /* Catch specific keywords.  Should be done with a data structure.  */
  2105.   switch (namelen)
  2106.     {
  2107.     case 8:
  2108.       if (!strncmp (tokstart, "unsigned", 8))
  2109.     return UNSIGNED;
  2110.       break;
  2111.     case 6:
  2112.       if (!strncmp (tokstart, "struct", 6))
  2113.     return STRUCT;
  2114.       if (!strncmp (tokstart, "signed", 6))
  2115.     return SIGNED;
  2116.       if (!strncmp (tokstart, "sizeof", 6))      
  2117.     return SIZEOF;
  2118.       break;
  2119.     case 5:
  2120.       if (!strncmp (tokstart, "union", 5))
  2121.     return UNION;
  2122.       if (!strncmp (tokstart, "short", 5))
  2123.     return SHORT;
  2124.       break;
  2125.     case 4:
  2126.       if (!strncmp (tokstart, "enum", 4))
  2127.     return ENUM;
  2128.       if (!strncmp (tokstart, "long", 4))
  2129.     return LONG;
  2130.       if (!strncmp (tokstart, "this", 4)
  2131.       && lookup_symbol ("$this", expression_context_block,
  2132.                 VAR_NAMESPACE, 0))
  2133.     return THIS;
  2134.       break;
  2135.     case 3:
  2136.       if (!strncmp (tokstart, "int", 3))
  2137.     return INT_KEYWORD;
  2138.       break;
  2139.     default:
  2140.       break;
  2141.     }
  2142.  
  2143.   yylval.sval.ptr = tokstart;
  2144.   yylval.sval.length = namelen;
  2145.  
  2146.   /* Any other names starting in $ are debugger internal variables.  */
  2147.  
  2148.   if (*tokstart == '$')
  2149.     {
  2150.       yylval.ivar = (struct internalvar *) lookup_internalvar (copy_name (yylval.sval) + 1);
  2151.       return VARIABLE;
  2152.     }
  2153.  
  2154.   /* Use token-type BLOCKNAME for symbols that happen to be defined as
  2155.      functions or symtabs.  If this is not so, then ...
  2156.      Use token-type TYPENAME for symbols that happen to be defined
  2157.      currently as names of types; NAME for other symbols.
  2158.      The caller is not constrained to care about the distinction.  */
  2159.   {
  2160.     char *tmp = copy_name (yylval.sval);
  2161.     struct symbol *sym;
  2162.  
  2163.     if (lookup_partial_symtab (tmp))
  2164.       return BLOCKNAME;
  2165.     sym = lookup_symbol (tmp, expression_context_block,
  2166.              VAR_NAMESPACE, 0);
  2167.     if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
  2168.       return BLOCKNAME;
  2169.     if (lookup_typename (copy_name (yylval.sval), expression_context_block, 1))
  2170.       return TYPENAME;
  2171.     return NAME;
  2172.   }
  2173. }
  2174.  
  2175. static void
  2176. yyerror ()
  2177. {
  2178.   error ("Invalid syntax in expression.");
  2179. }
  2180.  
  2181. /* Return a null-terminated temporary copy of the name
  2182.    of a string token.  */
  2183.  
  2184. static char *
  2185. copy_name (token)
  2186.      struct stoken token;
  2187. {
  2188.   bcopy (token.ptr, namecopy, token.length);
  2189.   namecopy[token.length] = 0;
  2190.   return namecopy;
  2191. }
  2192.  
  2193. /* Reverse an expression from suffix form (in which it is constructed)
  2194.    to prefix form (in which we can conveniently print or execute it).  */
  2195.  
  2196. static void prefixify_subexp ();
  2197.  
  2198. static void
  2199. prefixify_expression (expr)
  2200.      register struct expression *expr;
  2201. {
  2202.   register int len = sizeof (struct expression) +
  2203.                     expr->nelts * sizeof (union exp_element);
  2204.   register struct expression *temp;
  2205.   register int inpos = expr->nelts, outpos = 0;
  2206.  
  2207.   temp = (struct expression *) alloca (len);
  2208.  
  2209.   /* Copy the original expression into temp.  */
  2210.   bcopy (expr, temp, len);
  2211.  
  2212.   prefixify_subexp (temp, expr, inpos, outpos);
  2213. }
  2214.  
  2215. /* Return the number of exp_elements in the subexpression of EXPR
  2216.    whose last exp_element is at index ENDPOS - 1 in EXPR.  */
  2217.  
  2218. static int
  2219. length_of_subexp (expr, endpos)
  2220.      register struct expression *expr;
  2221.      register int endpos;
  2222. {
  2223.   register int oplen = 1;
  2224.   register int args = 0;
  2225.   register int i;
  2226.  
  2227.   if (endpos < 0)
  2228.     error ("?error in length_of_subexp");
  2229.  
  2230.   i = (int) expr->elts[endpos - 1].opcode;
  2231.  
  2232.   switch (i)
  2233.     {
  2234.       /* C++  */
  2235.     case OP_SCOPE:
  2236.       oplen = 4 + ((expr->elts[endpos - 2].longconst
  2237.             + sizeof (union exp_element))
  2238.            / sizeof (union exp_element));
  2239.       break;
  2240.  
  2241.     case OP_LONG:
  2242.     case OP_DOUBLE:
  2243.       oplen = 4;
  2244.       break;
  2245.  
  2246.     case OP_VAR_VALUE:
  2247.     case OP_LAST:
  2248.     case OP_REGISTER:
  2249.     case OP_INTERNALVAR:
  2250.       oplen = 3;
  2251.       break;
  2252.  
  2253.     case OP_FUNCALL:
  2254.       oplen = 3;
  2255.       args = 1 + expr->elts[endpos - 2].longconst;
  2256.       break;
  2257.  
  2258.     case UNOP_CAST:
  2259.     case UNOP_MEMVAL:
  2260.       oplen = 3;
  2261.       args = 1;
  2262.       break;
  2263.  
  2264.     case STRUCTOP_STRUCT:
  2265.     case STRUCTOP_PTR:
  2266.       args = 1;
  2267.     case OP_STRING:
  2268.       oplen = 3 + ((expr->elts[endpos - 2].longconst
  2269.             + sizeof (union exp_element))
  2270.            / sizeof (union exp_element));
  2271.       break;
  2272.  
  2273.     case TERNOP_COND:
  2274.       args = 3;
  2275.       break;
  2276.  
  2277.     case BINOP_ASSIGN_MODIFY:
  2278.       oplen = 3;
  2279.       args = 2;
  2280.       break;
  2281.  
  2282.       /* C++ */
  2283.     case OP_THIS:
  2284.       oplen = 2;
  2285.       break;
  2286.  
  2287.     default:
  2288.       args = 1 + (i < (int) BINOP_END);
  2289.     }
  2290.  
  2291.   while (args > 0)
  2292.     {
  2293.       oplen += length_of_subexp (expr, endpos - oplen);
  2294.       args--;
  2295.     }
  2296.  
  2297.   return oplen;
  2298. }
  2299.  
  2300. /* Copy the subexpression ending just before index INEND in INEXPR
  2301.    into OUTEXPR, starting at index OUTBEG.
  2302.    In the process, convert it from suffix to prefix form.  */
  2303.  
  2304. static void
  2305. prefixify_subexp (inexpr, outexpr, inend, outbeg)
  2306.      register struct expression *inexpr;
  2307.      struct expression *outexpr;
  2308.      register int inend;
  2309.      int outbeg;
  2310. {
  2311.   register int oplen = 1;
  2312.   register int args = 0;
  2313.   register int i;
  2314.   int *arglens;
  2315.   enum exp_opcode opcode;
  2316.  
  2317.   /* Compute how long the last operation is (in OPLEN),
  2318.      and also how many preceding subexpressions serve as
  2319.      arguments for it (in ARGS).  */
  2320.  
  2321.   opcode = inexpr->elts[inend - 1].opcode;
  2322.   switch (opcode)
  2323.     {
  2324.       /* C++  */
  2325.     case OP_SCOPE:
  2326.       oplen = 4 + ((inexpr->elts[inend - 2].longconst
  2327.             + sizeof (union exp_element))
  2328.            / sizeof (union exp_element));
  2329.       break;
  2330.  
  2331.     case OP_LONG:
  2332.     case OP_DOUBLE:
  2333.       oplen = 4;
  2334.       break;
  2335.  
  2336.     case OP_VAR_VALUE:
  2337.     case OP_LAST:
  2338.     case OP_REGISTER:
  2339.     case OP_INTERNALVAR:
  2340.       oplen = 3;
  2341.       break;
  2342.  
  2343.     case OP_FUNCALL:
  2344.       oplen = 3;
  2345.       args = 1 + inexpr->elts[inend - 2].longconst;
  2346.       break;
  2347.  
  2348.     case UNOP_CAST:
  2349.     case UNOP_MEMVAL:
  2350.       oplen = 3;
  2351.       args = 1;
  2352.       break;
  2353.  
  2354.     case STRUCTOP_STRUCT:
  2355.     case STRUCTOP_PTR:
  2356.       args = 1;
  2357.     case OP_STRING:
  2358.       oplen = 3 + ((inexpr->elts[inend - 2].longconst
  2359.             + sizeof (union exp_element))
  2360.            / sizeof (union exp_element));
  2361.            
  2362.       break;
  2363.  
  2364.     case TERNOP_COND:
  2365.       args = 3;
  2366.       break;
  2367.  
  2368.     case BINOP_ASSIGN_MODIFY:
  2369.       oplen = 3;
  2370.       args = 2;
  2371.       break;
  2372.  
  2373.       /* C++ */
  2374.     case OP_THIS:
  2375.       oplen = 2;
  2376.       break;
  2377.  
  2378.     default:
  2379.       args = 1 + ((int) opcode < (int) BINOP_END);
  2380.     }
  2381.  
  2382.   /* Copy the final operator itself, from the end of the input
  2383.      to the beginning of the output.  */
  2384.   inend -= oplen;
  2385.   bcopy (&inexpr->elts[inend], &outexpr->elts[outbeg],
  2386.      oplen * sizeof (union exp_element));
  2387.   outbeg += oplen;
  2388.  
  2389.   /* Find the lengths of the arg subexpressions.  */
  2390.   arglens = (int *) alloca (args * sizeof (int));
  2391.   for (i = args - 1; i >= 0; i--)
  2392.     {
  2393.       oplen = length_of_subexp (inexpr, inend);
  2394.       arglens[i] = oplen;
  2395.       inend -= oplen;
  2396.     }
  2397.  
  2398.   /* Now copy each subexpression, preserving the order of
  2399.      the subexpressions, but prefixifying each one.
  2400.      In this loop, inend starts at the beginning of
  2401.      the expression this level is working on
  2402.      and marches forward over the arguments.
  2403.      outbeg does similarly in the output.  */
  2404.   for (i = 0; i < args; i++)
  2405.     {
  2406.       oplen = arglens[i];
  2407.       inend += oplen;
  2408.       prefixify_subexp (inexpr, outexpr, inend, outbeg);
  2409.       outbeg += oplen;
  2410.     }
  2411. }
  2412.  
  2413. /* This page contains the two entry points to this file.  */
  2414.  
  2415. /* Read a C expression from the string *STRINGPTR points to,
  2416.    parse it, and return a pointer to a  struct expression  that we malloc.
  2417.    Use block BLOCK as the lexical context for variable names;
  2418.    if BLOCK is zero, use the block of the selected stack frame.
  2419.    Meanwhile, advance *STRINGPTR to point after the expression,
  2420.    at the first nonwhite character that is not part of the expression
  2421.    (possibly a null character).
  2422.  
  2423.    If COMMA is nonzero, stop if a comma is reached.  */
  2424.  
  2425. struct expression *
  2426. parse_c_1 (stringptr, block, comma)
  2427.      char **stringptr;
  2428.      struct block *block;
  2429. {
  2430.   struct cleanup *old_chain;
  2431.  
  2432.   lexptr = *stringptr;
  2433.  
  2434.   paren_depth = 0;
  2435.   type_stack_depth = 0;
  2436.  
  2437.   comma_terminates = comma;
  2438.  
  2439.   if (lexptr == 0 || *lexptr == 0)
  2440.     error_no_arg ("expression to compute");
  2441.  
  2442.   old_chain = make_cleanup (free_funcalls, 0);
  2443.   funcall_chain = 0;
  2444.  
  2445.   expression_context_block = block ? block : get_selected_block ();
  2446.  
  2447.   namecopy = (char *) alloca (strlen (lexptr) + 1);
  2448.   expout_size = 10;
  2449.   expout_ptr = 0;
  2450.   expout = (struct expression *)
  2451.     xmalloc (sizeof (struct expression)
  2452.          + expout_size * sizeof (union exp_element));
  2453.   make_cleanup (free_current_contents, &expout);
  2454.   if (yyparse ())
  2455.     yyerror ();
  2456.   discard_cleanups (old_chain);
  2457.   expout->nelts = expout_ptr;
  2458.   expout = (struct expression *)
  2459.     xrealloc (expout,
  2460.           sizeof (struct expression)
  2461.           + expout_ptr * sizeof (union exp_element));
  2462.   prefixify_expression (expout);
  2463.   *stringptr = lexptr;
  2464.   return expout;
  2465. }
  2466.  
  2467. /* Parse STRING as an expression, and complain if this fails
  2468.    to use up all of the contents of STRING.  */
  2469.  
  2470. struct expression *
  2471. parse_c_expression (string)
  2472.      char *string;
  2473. {
  2474.   register struct expression *exp;
  2475.   exp = parse_c_1 (&string, 0, 0);
  2476.   if (*string)
  2477.     error ("Junk after end of expression.");
  2478.   return exp;
  2479. }
  2480.  
  2481. static void 
  2482. push_type (tp)
  2483.      enum type_pieces tp;
  2484. {
  2485.   if (type_stack_depth == type_stack_size)
  2486.     {
  2487.       type_stack_size *= 2;
  2488.       type_stack = (enum type_pieces *)
  2489.     xrealloc (type_stack, type_stack_size * sizeof (enum type_pieces));
  2490.     }
  2491.   type_stack[type_stack_depth++] = tp;
  2492. }
  2493.  
  2494. static enum type_pieces 
  2495. pop_type ()
  2496. {
  2497.   if (type_stack_depth)
  2498.     return type_stack[--type_stack_depth];
  2499.   return tp_end;
  2500. }
  2501.  
  2502. void
  2503. _initialize_expread ()
  2504. {
  2505.   type_stack_size = 80;
  2506.   type_stack_depth = 0;
  2507.   type_stack = (enum type_pieces *)
  2508.     xmalloc (type_stack_size * sizeof (enum type_pieces));
  2509. }
  2510.